package edu.zcmu.seckill.controller;


import edu.zcmu.seckill.response.R;
import edu.zcmu.seckill.service.OrderService;
import edu.zcmu.seckill.vo.GenerateOrderVo;
import edu.zcmu.seckill.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 唐诗
 * @since 2022-02-22
 */
@RestController
@RequestMapping("/seckill/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @PostMapping("/placeOrder")
    public R placeOrder(@RequestBody Map<String,Integer> map,HttpServletRequest request){
        return orderService.placeOrder(map.get("id"),request);
    }


    @PostMapping("/getOrderInfo")
    public R getOrderInfo(@RequestBody OrderVo orderVo,HttpServletRequest request){
        return orderService.getOrderInfo(orderVo,request);
    }

    @PostMapping("/generateNormalOrder")
    public R payNormalOrder(@RequestBody OrderVo orderVo, HttpServletRequest request){
        Boolean s = orderService.payNormalOrder(orderVo, request);
        if (s==null){
            return R.error().message("支付失败");
        }else{
            return R.ok();
        }
    }
}
